import Koa from "koa";
import koaStatic from "koa-static";
import router from "./router";
import config from "./config";
import middleWare from "./middleware/index";
import kosCors from "./middleware/koa-cors";
import bodyParser from "koa-bodyparser";
import http from "http"; //node内置模块
const port = config.server.port;
const app = new Koa();
middleWare(app);
app.use(kosCors);
app.use(bodyParser());
app.use(koaStatic("./static"));
app.use(router.routes());

app.use(async (ctx) => {
  ctx.body = "Hello world!";
});
// ------------方式1--------------
// app.listen(port);

// ------------方式2---------------
// 为使得ws共用端口
const server = http.createServer(app.callback());
server.listen(port);

console.log(`Http Server running on port ${port}`);
